package top.rainf.support;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 星环
 * @date 2023/5/6 20:18:43
 * @description
 */
public class VerifyUtil {
    //...@... . ...@前支持a-z,A-Z,_-.
    private static final String EMAIL_VERIFY_REGEXP = "^([a-zA-Z\\d_-]|\\.)+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$";

    /**
     * 验证是不是合理的邮件
     * @param email
     * @return
     */
    public static boolean isValidEmail(String email){
        Pattern pattern = Pattern.compile(EMAIL_VERIFY_REGEXP);
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    }

    public static String  checkToken(String token,int userId){
        int userIdFromToken = TokenGenerator.getUserIdFromToken(token);
        if(userIdFromToken == userId){
            return "";
        }
        return "token不一致";
    }
}
